home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / GLE / PORT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  7.3 KB  |  297 lines

  1.  
  2. /*
  3.  * port.h 
  4.  *
  5.  * FUNCTION:
  6.  * This file contains defines for porting the tubing toolkit from GL to
  7.  * OpenGL to some callback scheme.
  8.  *
  9.  * HISTORY:
  10.  * Created by Linas Vepstas --  February 1993
  11.  * Added auto texture coord generation hacks, Linas April 1994 
  12.  */
  13.  
  14. #ifndef __GLE_PORT_H__
  15. #define __GLE_PORT_H__
  16.  
  17.  
  18. #ifndef TRUE
  19. #define TRUE 1
  20. #endif
  21.  
  22. #ifndef FALSE
  23. #define FALSE 0
  24. #endif
  25.  
  26. #ifndef M_PI
  27. #define M_PI 3.14159265358979323846
  28. #endif
  29.  
  30. /* ====================================================== */
  31. /* Some compilers can't handle multiply-subscripted array's */
  32.  
  33. #ifdef FUNKY_C
  34. typedef gleDouble gleVector;
  35. #define AVAL(arr,n,i,j)  arr(6*n+3*i+j)
  36. #define VVAL(arr,n,i)  arr(3*n+i)
  37.  
  38. #else  /* FUNKY_C */
  39. typedef double gleVector[3];
  40. typedef double glePoint[2];
  41. #define AVAL(arr,n,i,j)  arr[n][i][j]
  42. #define VVAL(arr,n,i)  arr[n][i];
  43.  
  44. #endif /* FUNKY_C */
  45.  
  46. /* ====================================================== */
  47. /* These are used to convey info about topography to the 
  48.  * texture mapping routines */
  49.  
  50. #define FRONT         1
  51. #define BACK         2
  52. #define FRONT_CAP     3
  53. #define BACK_CAP    4
  54. #define FILLET        5
  55.  
  56. /* ====================================================== */
  57.  
  58. #define __GLE_DOUBLE
  59.  
  60. /* ====================================================== */
  61.  
  62. #ifdef __GLE_DOUBLE
  63. #define gleDouble         double
  64. #define urot_axis(a,b,c)     urot_axis_d(a,b,c)
  65. #define uview_direction(a,b,c)     uview_direction_d(a,b,c)
  66. #define uviewpoint(a,b,c,d)     uviewpoint_d(a,b,c,d)
  67. #define MULTMATRIX(m)        MULTMATRIX_D(m)
  68. #define LOADMATRIX(m)        LOADMATRIX_D(m)
  69. #define V3F(x,j,id)        V3F_D(x,j,id)
  70. #define N3F(x)            N3F_D(x)
  71. #define T2F(x,y)        T2F_D(x,y)
  72. #else 
  73. #define gleDouble         float
  74. #define urot_axis(a,b,c)     urot_axis_f(a,b,c)
  75. #define uview_direction(a,b,c)     uview_direction_f(a,b,c)
  76. #define uviewpoint(a,b,c,d)     uviewpoint_f(a,b,c,d)
  77. #define MULTMATRIX(m)        MULTMATRIX_F(m)
  78. #define LOADMATRIX(m)        LOADMATRIX_F(m)
  79. #define V3F(x,j,id)        V3F_F(x,j,id)
  80. #define N3F(x)            N3F_F(x)
  81. #define T2F(x,y)        T2F_F(x,y)
  82. #endif 
  83.  
  84. /* ====================================================== */
  85.  
  86. #if (defined DEBUG_GL_32 || DEBUG_OPENGL_10)
  87. #undef GL_32
  88. #undef OPENGL_10
  89.  
  90. #define BGNTMESH(i,len)    printf ("bgntmesh() \n");
  91. #define ENDTMESH()      printf ("endtmesh() \n");
  92. #define BGNPOLYGON()    printf ("bgnpolygon() \n");
  93. #define ENDPOLYGON()    printf ("endpolygon() \n");
  94. #define V3F_F(x,j,id)    printf ("v3f(x)        %f %f %f \n", x[0], x[1], x[2]);
  95. #define V3F_D(x,j,id)    printf ("v3d(x)     %f %f %f \n", x[0], x[1], x[2]);
  96. #define    N3F_F(x)    printf ("n3f(x)     %f %f %f \n", x[0], x[1], x[2]);
  97. #define    N3F_D(x)    printf ("n3d(x)        %f %f %f \n", x[0], x[1], x[2]);
  98. #define    C3F(x)        printf ("c3f(x)     %f %f %f \n", x[0], x[1], x[2]);
  99.  
  100. #define    POPMATRIX()    printf ("popmatrix () \n");
  101. #define    PUSHMATRIX()    printf ("pushmatrix() \n");
  102. #define    MULTMATRIX_F(x)    MULTMATRIX_D(x)
  103. #define    LOADMATRIX_F(x)    LOADMATRIX_D(x)
  104.  
  105.  
  106. #define LOADMATRIX_D(x) {                \
  107.    int i, j;                         \
  108.    printf ("loadmatrix (x) \n");            \
  109.    for (i=0; i<4; i++) {                \
  110.       for (j=0; j<4; j++) {                \
  111.          printf ( "%f ", x[i][j]);            \
  112.       }                            \
  113.       printf (" \n");                    \
  114.    }                            \
  115. }
  116.  
  117. #define MULTMATRIX_D(x) {                \
  118.    int i, j;                         \
  119.    printf ("multmatrix (x) \n");            \
  120.    for (i=0; i<4; i++) {                \
  121.       for (j=0; j<4; j++) {                \
  122.          printf ( "%f ", x[i][j]);            \
  123.       }                            \
  124.       printf (" \n");                    \
  125.    }                            \
  126. }
  127.  
  128. #define __IS_LIGHTING_ON  (1)
  129.  
  130. #endif
  131.  
  132. /* ====================================================== */
  133.  
  134. #ifdef GL_32
  135.  
  136. #include <gl/gl.h>
  137.  
  138. #define BGNTMESH(i,len)    bgntmesh()
  139. #define ENDTMESH()    endtmesh()
  140. #define BGNPOLYGON()    bgnpolygon()
  141. #define ENDPOLYGON()    endpolygon()
  142. #define V3F_F(x,j,id)    v3f(x)
  143. #define V3F_D(x,j,id)    v3d(x)
  144. #define    N3F_F(x)    n3f(x)
  145. #define    T2F_F(x,y)
  146. #define    T2F_D(x,y)
  147. #define    C3F(x)        c3f(x)
  148.  
  149. #define    POPMATRIX()    popmatrix ()
  150. #define    PUSHMATRIX()    pushmatrix()
  151. #define    MULTMATRIX_F(x)    multmatrix (x)
  152. #define    LOADMATRIX_F(x)    loadmatrix (x)
  153.  
  154. #define    N3F_D(x) {                    \
  155.    float nnn[3];                    \
  156.    nnn[0] = (float) x[0];                 \
  157.    nnn[1] = (float) x[1];                 \
  158.    nnn[2] = (float) x[2];                 \
  159.    n3f (nnn);                        \
  160. }
  161.  
  162. #define LOADMATRIX_D(x) {                \
  163.    int i, j;                         \
  164.    float mmm[4][4];                    \
  165.    for (i=0; i<4; i++) {                \
  166.       for (j=0; j<4; j++) {                \
  167.          mmm[i][j] = (float) x[i][j];            \
  168.       }                            \
  169.    }                            \
  170.    loadmatrix(mmm);                    \
  171. }
  172.  
  173. #define MULTMATRIX_D(x) {                \
  174.    int i, j;                         \
  175.    float mmm[4][4];                    \
  176.    for (i=0; i<4; i++) {                \
  177.       for (j=0; j<4; j++) {                \
  178.          mmm[i][j] = (float) x[i][j];            \
  179.       }                            \
  180.    }                            \
  181.    multmatrix(mmm);                    \
  182. }
  183.  
  184. /* #define __IS_LIGHTING_ON  (MSINGLE == getmmode()) */
  185. #define __IS_LIGHTING_ON  (extrusion_join_style & TUBE_LIGHTING_ON)
  186.  
  187. #endif /* GL_32 */
  188.  
  189. /* ====================================================== */
  190. #ifdef OPENGL_10
  191.  
  192. #if defined(_WIN32)
  193. #include <windows.h>
  194. #pragma warning (disable:4244)          /* disable bogus conversion warnings */
  195. #endif
  196. #include <GL/gl.h>
  197. #include <GL/glu.h>
  198.  
  199. /*
  200. #define    N3F_F(x) {                    \
  201.    float nnn[3];                    \
  202.    nnn[0] = - (float) x[0];                 \
  203.    nnn[1] = - (float) x[1];                 \
  204.    nnn[2] = - (float) x[2];                 \
  205.    glNormal3fv (nnn);                        \
  206. }
  207. #define    N3F_D(x) {                    \
  208.    float nnn[3];                    \
  209.    nnn[0] = - (float) x[0];                 \
  210.    nnn[1] = - (float) x[1];                 \
  211.    nnn[2] = - (float) x[2];                 \
  212.    glNormal3fv (nnn);                        \
  213. }
  214. */
  215.  
  216. #define    C3F(x)        glColor3fv(x)
  217. #define    T2F_F(x,y)    glTexCoord2f(x,y)
  218. #define    T2F_D(x,y)    glTexCoord2d(x,y)
  219.  
  220. #define    POPMATRIX()    glPopMatrix()
  221. #define    PUSHMATRIX()    glPushMatrix()
  222.  
  223. #define    MULTMATRIX_F(x)    glMultMatrixf ((const GLfloat *)x)
  224. #define    LOADMATRIX_F(x)    glLoadMatrixf ((const GLfloat *)x)
  225.  
  226. #define    MULTMATRIX_D(x)    glMultMatrixd ((const GLdouble *)x)
  227. #define    LOADMATRIX_D(x)    glLoadMatrixd ((const GLdouble *)x)
  228.  
  229. #define __IS_LIGHTING_ON  (glIsEnabled(GL_LIGHTING))
  230.  
  231. /* ====================================================== */
  232. #ifdef AUTO_TEXTURE
  233.  
  234. #define BGNTMESH(i,len) {                     \
  235.     if(_gle_gc -> bgn_gen_texture) (*(_gle_gc -> bgn_gen_texture))(i,len);\
  236.     glBegin (GL_TRIANGLE_STRIP);             \
  237. }
  238.  
  239. #define BGNPOLYGON() {                     \
  240.     if(_gle_gc -> bgn_gen_texture) (*(_gle_gc -> bgn_gen_texture))();\
  241.     glBegin (GL_POLYGON);                \
  242. }
  243.  
  244. #define N3F_F(x) {                     \
  245.     if(_gle_gc -> n3f_gen_texture) (*(_gle_gc -> n3f_gen_texture))(x); \
  246.     glNormal3fv(x);                 \
  247. }
  248.  
  249. #define N3F_D(x) {                     \
  250.     if(_gle_gc -> n3d_gen_texture) (*(_gle_gc -> n3d_gen_texture))(x); \
  251.     glNormal3dv(x);                 \
  252. }
  253.  
  254. #define V3F_F(x,j,id) {                     \
  255.     if(_gle_gc -> v3f_gen_texture) (*(_gle_gc -> v3f_gen_texture))(x,j,id);\
  256.     glVertex3fv(x);                 \
  257. }
  258.  
  259. #define V3F_D(x,j,id) {                     \
  260.     if(_gle_gc -> v3d_gen_texture) (*(_gle_gc -> v3d_gen_texture))(x,j,id); \
  261.     glVertex3dv(x);                 \
  262. }
  263.  
  264. #define ENDTMESH() {                    \
  265.     if(_gle_gc -> end_gen_texture) (*(_gle_gc -> end_gen_texture))(); \
  266.     glEnd ();                    \
  267. }
  268.  
  269. #define ENDPOLYGON() {                    \
  270.     if(_gle_gc -> end_gen_texture) (*(_gle_gc -> end_gen_texture))(); \
  271.     glEnd ();                    \
  272. }
  273.  
  274. /* ====================================================== */
  275. #else /* AUTO_TEXTURE */
  276.  
  277. #define BGNTMESH(i,len)    glBegin (GL_TRIANGLE_STRIP);
  278. #define BGNPOLYGON()     glBegin (GL_POLYGON);
  279.  
  280. #define    N3F_F(x)    glNormal3fv(x)
  281. #define    N3F_D(x)    glNormal3dv(x)
  282. #define V3F_F(x,j,id)    glVertex3fv(x);
  283. #define V3F_D(x,j,id)    glVertex3dv(x);
  284.  
  285. #define ENDTMESH()    glEnd ()
  286. #define ENDPOLYGON()    glEnd()
  287.  
  288. #endif /* AUTO_TEXTURE */
  289.  
  290. #endif /* OPENGL_10 */
  291.  
  292. /* ====================================================== */
  293.  
  294.  
  295. #endif /* __GLE_PORT_H__ */
  296. /* ================== END OF FILE ======================= */
  297.